"""
@project:StrategyBacktestEngine
@author:liuzeyu
@time:2022-09-08
@version:v0.0.1
"""
import matplotlib.pyplot as plt
import pandas as pd


def plot_stock(title, start, end, data='shdata.csv'):
    plt.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False

    # download data from tushare
    # dd = ts.get_k_data(code, autype='qfq', start=start, end=end)

    # using local data
    dd = pd.read_csv(data)

    dd.index = pd.to_datetime(dd.date)
    dd.close.plot(figsize=(14, 6), color='r')
    plt.title(title + '\n' + start + ':' + end, size=15)
    plt.annotate(f'期间累计涨幅:{(dd.close[-1] / dd.close[0] - 1) * 100:.2f}%', xy=(dd.index[-150], dd.close.mean()), xytext=(dd.index[-500], dd.close.min()), bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5), arrowprops=dict(facecolor='green', shrink=0.05), fontsize=12)
    plt.show()


def plot_stock2(code, title, start, end):
    dd = ts.get_k_data(code, autype='qfq', start=start, end=end)
    dd.index = pd.to_datetime(dd.date)
    dd.close.plot(figsize=(14, 6), color='r')
    plt.title(title + '价格走势\n' + start + ':' + end, size=15)
    plt.annotate(f'期间累计涨幅:{(dd.close[-1] / dd.close[0] - 1) * 100:.2f}%', xy=(dd.index[-150], dd.close.mean()),
                 xytext=(dd.index[-500], dd.close.min()), bbox=dict(boxstyle='round,pad=0.5',
                                                                    fc='yellow', alpha=0.5),
                 arrowprops=dict(facecolor='green', shrink=0.05), fontsize=12)
    plt.show()
